﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StereoFfdShowSubEngine.cs" company="ScRePt">
//   Copyright © ScRePt 2010 - 2012
// </copyright>
// <summary>
//   The stereo ffd show sub engine.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace MP3D.Subtitles
{
    #region Using Directives

    using System.Reflection;

    using FFDShow;

    using MediaPortal.Player.Subtitles;

    #endregion

    /// <summary>
    /// The stereo ffd show sub engine.
    /// </summary>
    public class StereoFfdShowSubEngine : StereoSubEngine
    {
        #region Constants and Fields

        /// <summary>
        /// The ffdshow api.
        /// </summary>
        private readonly FFDShowAPI ffdshowApi;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="StereoFfdShowSubEngine"/> class.
        /// </summary>
        /// <param name="baseEngine">
        /// The base engine.
        /// </param>
        public StereoFfdShowSubEngine(ISubEngine baseEngine)
            : base(baseEngine)
        {
            FieldInfo inf = baseEngine.GetType().GetField("ffdshowAPI", BindingFlags.NonPublic | BindingFlags.Instance);

            if (inf == null)
            {
                return;
            }

            this.ffdshowApi = (FFDShowAPI)inf.GetValue(baseEngine);

            if (this.ffdshowApi == null)
            {
                return;
            }

            this.ffdshowApi.setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subStereoscopic, 1);
        }

        /// <summary>
        /// Finalizes an instance of the <see cref="StereoFfdShowSubEngine"/> class. 
        /// </summary>
        ~StereoFfdShowSubEngine()
        {
            if (this.ffdshowApi == null)
            {
                return;
            }

            this.ffdshowApi.setIntParam(FFDShowConstants.FFDShowDataId.IDFF_subStereoscopic, 0);
        }

        #endregion
    }
}